<?php

namespace App\Console\Commands\Tools\OpenShop\Contract;

use App\Enums\OpenShop\InvestmentPromotion\MainProcessEnum;
use App\Enums\OpenShop\InvestmentPromotion\SignOrderEnum;
use App\Enums\OpenShop\MissionTemplateEnum;
use App\Models\OpenShop\InvestmentPromotion\OpenShopSignOrderModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopSignOrderPermissionAnchorModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopSiteMissionModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopUserContractModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopUserExtContractModel;
use App\Models\OpenShop\SiteLocation\OpenShopSiteLocationModel;
use App\Service\OpenShop\Feishu\ShopManualService;
use App\Service\OpenShop\OrderService;
use Illuminate\Console\Command;

class ChangeContractSignVersion extends Command
{
    protected $signature   = 'tools:open_shop:change_contract_sign_version {orderNo} {version}';
    protected $description = '刷新合同版本号';

    public function handle()
    {
        $orderNo = $this->argument('orderNo');

        $version = $this->argument('version');

        $openShopOrderSign = OpenShopSignOrderModel::query()->where('orderNo', $orderNo)->first();
        $openShopContract  = OpenShopUserContractModel::query()->where('orderNo', $orderNo)->first();

        switch ($version) {
            case 3:
            case '3.0':
                $signTime = strtotime('2022-10-01 10:00:01');
                $version  = 1;
                break;
            case 4:
            case '4.0':
                $signTime = strtotime('2022-10-01 10:00:01');
                $version  = 2;
                break;
            default:
                $this->error('版本号错误,请重新再填');
                return;
        }


        $openShopOrderSign->signTime = $signTime;
        $openShopOrderSign->save();
        $openShopContract->version = $version;
        $openShopContract->save();

        OpenShopUserExtContractModel::query()->where('contractId', $openShopContract->id)
                                    ->update(['signTime' => $signTime]);

        $this->info('订单已调整至 ' . $version);

    }
}
